package com.flex.mobile.timer;

import com.flex.mobile.constant.OrderInfoStatusConst;
import com.flex.mobile.dao.impl.CustInfoDao;
import com.flex.mobile.dao.impl.OrderInfoDao;
import com.flex.mobile.dao.model.CustInfo;
import com.flex.mobile.dao.model.OrderInfo;
import com.flex.mobile.dao.model.TaxiTimer;
import com.flex.mobile.manager.FeedManager;
import com.flex.mobile.model.OrderMessage;
import com.flex.mobile.util.SpringContextUtil;

public class WFTimerHandler implements TimerHandler {
   private OrderInfoDao orderDao = (OrderInfoDao)SpringContextUtil.getBean("orderInfoDao");
   private CustInfoDao userDao = (CustInfoDao)SpringContextUtil.getBean("custInfoDao");
   private FeedManager feedManager = (FeedManager)SpringContextUtil.getBean("feedManager");
   
   public void handlerTimer(final TaxiTimer timer) {
      if (timer.getTimerKind().equals(WFTimerKind.ORDER_PRETIME)) {
         long orderId = Long.parseLong(timer.getObjectID());
         OrderInfo order = orderDao.findById(orderId);
         order.setOrderStatus(OrderInfoStatusConst.LOCKED);
         orderDao.update(order);
         
         CustInfo user = userDao.findById(order.getOwnerId());
         OrderMessage message = new OrderMessage();
         message.setType(OrderMessage.MESSAGE_TYPE_REMIND);
         feedManager.sendTaxiOrderMsg(message, user.getCellPhone1());
      }
      else {
         
      }
   }
}